package Eyjafjalla.action;

import Eyjafjalla.patch.CloudPatch;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.GainEnergyAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

import java.util.ArrayList;

public class InheritAction extends AbstractGameAction {
    public InheritAction(boolean upgrade){
        this.upgrade = upgrade;
        this.actionType = ActionType.CARD_MANIPULATION;
        duration = Settings.ACTION_DUR_FAST;
        startDuration = duration;
    }

    ArrayList<AbstractCard> cardToMove;
    int gainAmount;

    @Override
    public void update() {
        if(startDuration == duration){
            cardToMove = new ArrayList<>();
            int size = 10 - AbstractDungeon.player.hand.size();
            for(int i =0;i<size&&i<CloudPatch.cloudGroup.size();i++){
                cardToMove.add(CloudPatch.cloudGroup.group.get(i));
            }
            gainAmount = cardToMove.size();
//            if(upgrade)
//                addToTop(new GainCloudEnergyAction(gainAmount));
//            addToTop(new GainEnergyAction(gainAmount));
        }
        else if(cardToMove.size()>0){
            AbstractCard c = cardToMove.remove(0);
            CloudPatch.resetBeforeRemove(c);
            AbstractDungeon.player.hand.addToHand(c);
            AbstractDungeon.player.hand.refreshHandLayout();
            AbstractDungeon.player.hand.applyPowers();
        }

        tickDuration();
    }

    boolean upgrade;
}
